#include "audioplayer.h"
#include "ui_audioplayer.h"
const QString start="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n<html><body><p>Currently Playing:</p>";
const QString end="</body></html>";
AudioPlayer::AudioPlayer(QWidget *parent) :
    QWidget(parent),
    m_ui(new Ui::AudioPlayer)
{
    m_ui->setupUi(this);
    setMouseTracking(true);
    setStyleSheet("color: white; font-size: 25px; text-align:left");
}

AudioPlayer::~AudioPlayer()
{
    delete m_ui;
}

void AudioPlayer::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void AudioPlayer::setMediaFile(MediaFile * file) {

    // set Currently Playing info
    QString title=file->shortName;
    if(file->title!=""&&file->title.size()>0) { // check for empty file was added when debugging music playback bug
        title=file->title;
    }

    m_ui->label->setText(start+"<br /><p>"+title+"<br />By "+file->artist+"</p>"+end);

    // set Cover Art
    if(!file->coverArt.isNull())
        m_ui->image->setPixmap(QPixmap(file->coverArt).scaled(300,300,Qt::KeepAspectRatioByExpanding));
    else
        m_ui->image->setPixmap(QPixmap(":/imgs/3F00MediaFile.png").scaled(300,300,Qt::KeepAspectRatio));
}
